package com.control.qct.businesssteward.httputils;

import android.app.ProgressDialog;
import android.content.Context;
import android.text.TextUtils;
import android.util.Log;

import com.control.qct.businesssteward.model.AllAccountDetailModel;
import com.control.qct.businesssteward.model.BrandModel;
import com.control.qct.businesssteward.model.CheckBatchNoAndCheckersModel;
import com.control.qct.businesssteward.model.CheckDetailModel;
import com.control.qct.businesssteward.model.CheckOperateModel;
import com.control.qct.businesssteward.model.DayStatisticTableModel;
import com.control.qct.businesssteward.model.DoPayGoodsModel;
import com.control.qct.businesssteward.model.DoPayPromotionGoodsModel;
import com.control.qct.businesssteward.model.EverydayAccountModel;
import com.control.qct.businesssteward.model.GoodsChildTypeModel;
import com.control.qct.businesssteward.model.GoodsDetailModel;
import com.control.qct.businesssteward.model.GoodsModel;
import com.control.qct.businesssteward.model.GoodsParentTypeModel;
import com.control.qct.businesssteward.model.GoodsStatisticModel;
import com.control.qct.businesssteward.model.GuideModel;
import com.control.qct.businesssteward.model.LoginModel;
import com.control.qct.businesssteward.model.MemberInquireModel;
import com.control.qct.businesssteward.model.OpenOrderModel;
import com.control.qct.businesssteward.model.OrderDetailModel;
import com.control.qct.businesssteward.model.OrderListModel;
import com.control.qct.businesssteward.model.PaymentStyleModel;
import com.control.qct.businesssteward.model.StoreModel;
import com.control.qct.businesssteward.model.SubUnitsModel;
import com.control.qct.businesssteward.model.SupplierModel;
import com.control.qct.businesssteward.model.TypeStatisticModel;
import com.control.qct.businesssteward.utils.DialogUtil;
import com.control.qct.businesssteward.utils.SPUtils;
import com.lzy.okgo.model.HttpHeaders;

import org.json.JSONObject;

import java.io.File;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by Administrator on 2018/2/1 0001.
 */

public class NetProtocol {
    private static NetProtocol mNetProtocol;
    private ProgressDialog mProgressDialog;
    private HttpUtils mHttpUtils;
    private SPUtils mSPUtils;
    private RequestConfig mConfig;

    public NetProtocol(Context context) {
        mSPUtils = SPUtils.getInstance(context);
    }

    public static NetProtocol getInstance(Context context) {
        if (mNetProtocol == null) {
            mNetProtocol = new NetProtocol(context);
        }
        return mNetProtocol;
    }

    /**
     * 得到基本请求配置参数
     *
     * @return
     */
    private RequestConfig getBaseConfig(String url) {
        RequestConfig config = new RequestConfig();
        config.setWebAddress(FinalUrl.getURL() + "api/" + url);
        config.setHeaders(new HttpHeaders("Authorization", "Basic " + getNowToken()));
        return config;
    }

    /**
     * 获取userCode
     *
     * @return
     */
    public String getUserCode() {
        String userCode = mSPUtils.getString("user_code");
        if (TextUtils.isEmpty(userCode)) {
            return "";
        }
        return userCode;
    }

    /**
     * 获取token
     *
     * @return
     */
    public String getNowToken() {
        String token = mSPUtils.getString("token");
        if (TextUtils.isEmpty(token)) {
            return "";
        }
        return token;
    }

    /**
     * 登录
     *
     * @param params
     * @param httpResult
     */
    public void login(Context context, Map<String, String> params, String msg, HttpUtils.IHttpResult httpResult) {
        mProgressDialog = DialogUtil.getProgressDialog(context, msg);
        mHttpUtils = new HttpUtils(mProgressDialog, context);
        mConfig = getBaseConfig("session");
        mConfig.setCls(LoginModel.class);
        mConfig.setParams(params);
        mHttpUtils.postToJson(mConfig, httpResult);
    }

    /**
     * 退出登录
     *
     * @param context
     * @param httpResult
     */
    public void exits(Context context, HttpUtils.IHttpResult httpResult) {
        mProgressDialog = DialogUtil.getProgressDialog(context, "退出中...");
        mHttpUtils = new HttpUtils(mProgressDialog, context);
        mConfig = getBaseConfig("session");
        mHttpUtils.getToJson(mConfig, httpResult);
    }

    /**
     * 查询会员
     *
     * @param keyWord
     * @param httpResult
     */
    public void searchMember(Context context, String keyWord, HttpUtils.IHttpResult httpResult) {
        mProgressDialog = DialogUtil.getProgressDialog(context, "查询中...");
        mHttpUtils = new HttpUtils(mProgressDialog, context);
        mConfig = getBaseConfig("Member/GetMember?keyword=" + keyWord);
        mConfig.setCls(MemberInquireModel.class);
        mHttpUtils.getToJson(mConfig, httpResult);
    }

    /**
     * 获取导购员
     *
     * @param context
     * @param params
     * @param httpResult
     */
    public void getGuide(Context context, Map<String, String> params, HttpUtils.IHttpResult httpResult) {
        mProgressDialog = DialogUtil.getProgressDialog(context, "");
        mHttpUtils = new HttpUtils(mProgressDialog, context, false);
        mConfig = getBaseConfig("User/GetStoreSalers");
        mConfig.setCls(GuideModel.class);
        mConfig.setParams(params);
        mHttpUtils.postToJson(mConfig, httpResult);
    }

    /**
     * 获取商品列表
     *
     * @param context
     * @param params
     * @param httpResult
     */
    public void getGoodsList(Context context, Map<String, String> params, boolean isShow, HttpUtils.IHttpResult
            httpResult) {
        mProgressDialog = DialogUtil.getProgressDialog(context, "获取中...", false);
        mHttpUtils = new HttpUtils(mProgressDialog, context, isShow);
        mConfig = getBaseConfig("Product/GetProductList");
        mConfig.setCls(GoodsModel.class);
        mConfig.setParams(params);
        mHttpUtils.postToJson(mConfig, httpResult);
    }

    /**
     * 获取商品主类别
     *
     * @param context
     * @param httpResult
     */
    public void getGoodsParentType(Context context, HttpUtils.IHttpResult httpResult) {
        mProgressDialog = DialogUtil.getProgressDialog(context, "");
        mHttpUtils = new HttpUtils(mProgressDialog, context, false);
        mConfig = getBaseConfig("Product/GetRootCategorys");
        mConfig.setElement(GoodsParentTypeModel.class);
        mHttpUtils.getToJson(mConfig, httpResult);
    }

    /**
     * 获取商品子类别
     *
     * @param context
     * @param httpResult
     */
    public void getGoodsChildType(Context context, int position, HttpUtils.IHttpResult httpResult) {
        mProgressDialog = DialogUtil.getProgressDialog(context, "查询中...");
        mHttpUtils = new HttpUtils(mProgressDialog, context);
        mConfig = getBaseConfig("Product/GetChildCategorys?psn=" + position);
        mConfig.setElement(GoodsChildTypeModel.class);
        mHttpUtils.getToJson(mConfig, httpResult);
    }

    /**
     * 获取品牌
     *
     * @param context
     * @param httpResult
     */
    public void getBrands(Context context, boolean isShow, String title, int page, int rows, HttpUtils.IHttpResult
            httpResult) {
        mProgressDialog = DialogUtil.getProgressDialog(context, "查询中...");
        mHttpUtils = new HttpUtils(mProgressDialog, context, isShow);
        mConfig = getBaseConfig("Product/GetBrands?title=" + title + "&page=" + page + "&rows=" + rows);
        mConfig.setCls(BrandModel.class);
        mHttpUtils.getToJson(mConfig, httpResult);
    }

    /**
     * 获取最小计量单位
     *
     * @param context
     * @param httpResult
     */
    public void getSubunits(Context context, String title, HttpUtils.IHttpResult httpResult) {
        mProgressDialog = DialogUtil.getProgressDialog(context, "查询中...");
        mHttpUtils = new HttpUtils(mProgressDialog, context);
        mConfig = getBaseConfig("Product/GetSubUnits?title=" + title);
        mConfig.setElement(SubUnitsModel.class);
        mHttpUtils.getToJson(mConfig, httpResult);
    }

    /**
     * 获取供应商
     *
     * @param context
     * @param httpResult
     */
    public void getSuppliers(Context context, boolean isShow, String title, int page, int rows, HttpUtils.IHttpResult
            httpResult) {
        mProgressDialog = DialogUtil.getProgressDialog(context, "查询中...");
        mHttpUtils = new HttpUtils(mProgressDialog, context, isShow);
        mConfig = getBaseConfig("Product/GetSuppliers?title=" + title + "&page=" + page + "&rows=" + rows);
        mConfig.setCls(SupplierModel.class);
        mHttpUtils.getToJson(mConfig, httpResult);
    }

    /**
     * 获取支付列表
     *
     * @param context
     * @param httpResult
     */
    public void getPayList(Context context, HttpUtils.IHttpResult httpResult) {
        mProgressDialog = DialogUtil.getProgressDialog(context, "获取中...");
        mHttpUtils = new HttpUtils(mProgressDialog, context);
        mConfig = getBaseConfig("Pay/GetPayList");
        mConfig.setElement(PaymentStyleModel.class);
        mHttpUtils.getToJson(mConfig, httpResult);
    }

    /**
     * 获取商品详情
     *
     * @param context
     * @param httpResult
     */
    public void getGoodsDetail(Context context, int id, HttpUtils.IHttpResult httpResult) {
        mProgressDialog = DialogUtil.getProgressDialog(context, "获取中...");
        mHttpUtils = new HttpUtils(mProgressDialog, context);
        mConfig = getBaseConfig("Product/GetProductById/" + id);
        mConfig.setCls(GoodsDetailModel.class);
        mHttpUtils.getToJson(mConfig, httpResult);
    }

    /**
     * 删除商品
     *
     * @param context
     * @param httpResult
     */
    public void deleteGoods(Context context, int id, HttpUtils.IHttpResult httpResult) {
        mProgressDialog = DialogUtil.getProgressDialog(context, "正在删除...");
        mHttpUtils = new HttpUtils(mProgressDialog, context);
        mConfig = getBaseConfig("Product/RemoveProduct/" + id);
        mHttpUtils.getToJson(mConfig, httpResult);
    }


    /**
     * 上下架商品
     *
     * @param context
     * @param httpResult
     */
    public void setGoodsState(Context context, int id, int state, HttpUtils.IHttpResult httpResult) {
        mProgressDialog = DialogUtil.getProgressDialog(context, "正在修改...");
        mHttpUtils = new HttpUtils(mProgressDialog, context);
        mConfig = getBaseConfig("Product/SetProductState/" + id + "?state=" + state);
        mHttpUtils.getToJson(mConfig, httpResult);
    }

    /**
     * 新增或修改商品
     *
     * @param context
     * @param params
     * @param httpResult
     */
    public void addOrUpdateProduct(Context context, Map<String, String> params, List<String> file, HttpUtils
            .IHttpResult httpResult) {
        mProgressDialog = DialogUtil.getProgressDialog(context, "正在修改...");
        mHttpUtils = new HttpUtils(mProgressDialog, context);
        mConfig = getBaseConfig("Product/AddOrUpdateProduct/{Id}");
        Map<String, String> data = new HashMap<>();
        Map<String, File> fileMap = new HashMap<>();
        data.put("payload", new JSONObject(params).toString());
        Log.d("", "addOrUpdateProduct: " + new JSONObject(params).toString());
        for (int i = 0; i < file.size(); i++) {
            fileMap.put(file.get(i) + i, new File(file.get(i)));
        }
        mConfig.setParams(data);
        mConfig.setFile(fileMap);
        mHttpUtils.postFromData(mConfig, httpResult);
    }

    /**
     * 删除商品图片
     *
     * @param context
     * @param id
     * @param fileName
     * @param httpResult
     */
    public void removeProductImage(Context context, int id, String fileName, HttpUtils.IHttpResult httpResult) {
        mProgressDialog = DialogUtil.getProgressDialog(context, "正在删除...");
        mHttpUtils = new HttpUtils(mProgressDialog, context);
        mConfig = getBaseConfig("Product/RemoveProductImage/" + id + "?fileName=" + fileName);
        mHttpUtils.getToJson(mConfig, httpResult);
    }

    /**
     * 获取销售订单
     *
     * @param context
     * @param params
     * @param httpResult
     */
    public void getSaleOrderList(Context context, Map<String, String> params, boolean isShow, HttpUtils.IHttpResult
            httpResult) {
        mProgressDialog = DialogUtil.getProgressDialog(context, "获取中...");
        mHttpUtils = new HttpUtils(mProgressDialog, context, isShow);
        mConfig = getBaseConfig("SaleOrder/GetSaleOrderList");
        mConfig.setParams(params);
        mConfig.setCls(OrderListModel.class);
        mHttpUtils.postToJson(mConfig, httpResult);
    }

    /**
     * 获取销售订单详情
     *
     * @param context
     * @param httpResult
     */
    public void getSaleOrderDetail(Context context, String orderSn, HttpUtils.IHttpResult httpResult) {
        mProgressDialog = DialogUtil.getProgressDialog(context, "获取中...");
        mHttpUtils = new HttpUtils(mProgressDialog, context);
        mConfig = getBaseConfig("SaleOrder/GetSaleDetail?orderSndisp=" + orderSn);
        mConfig.setCls(OrderDetailModel.class);
        mHttpUtils.getToJson(mConfig, httpResult);
    }

    /**
     * 根据门店获取相关批次和盘点员列表
     *
     * @param context
     * @param httpResult
     */
    public void getCheckBatchNoAndCheckers(Context context, HttpUtils.IHttpResult httpResult) {
        mProgressDialog = DialogUtil.getProgressDialog(context, "获取中...");
        mHttpUtils = new HttpUtils(mProgressDialog, context, false);
        mConfig = getBaseConfig("TakeStock/GetCheckBatchnoAndCheckers");
        mConfig.setCls(CheckBatchNoAndCheckersModel.class);
        mHttpUtils.getToJson(mConfig, httpResult);
    }

    /**
     * 盘点明细列表
     *
     * @param context
     * @param httpResult
     */
    public void getTakeStockList(Context context, Map<String, String> params, boolean isShow, HttpUtils.IHttpResult
            httpResult) {
        mProgressDialog = DialogUtil.getProgressDialog(context, "获取中...");
        mHttpUtils = new HttpUtils(mProgressDialog, context, isShow);
        mConfig = getBaseConfig("TakeStock/GetTakestockList");
        mConfig.setCls(CheckDetailModel.class);
        mConfig.setParams(params);
        mHttpUtils.getToJson(mConfig, httpResult);
    }

    /**
     * 盘点日志列表
     *
     * @param context
     * @param httpResult
     */
    public void takeStockLogs(Context context, Map<String, String> params, HttpUtils.IHttpResult
            httpResult) {
        mProgressDialog = DialogUtil.getProgressDialog(context, "获取中...");
        mHttpUtils = new HttpUtils(mProgressDialog, context);
        mConfig = getBaseConfig("TakeStock/TakeStockLogs");
        mConfig.setElement(CheckOperateModel.class);
        mConfig.setParams(params);
        mHttpUtils.getToJson(mConfig, httpResult);
    }

    /**
     * 新增盘点
     *
     * @param context
     * @param httpResult
     */
    public void addTakeStock(Context context, Map<String, String> params, HttpUtils.IHttpResult
            httpResult) {
        mProgressDialog = DialogUtil.getProgressDialog(context, "修改中...");
        mHttpUtils = new HttpUtils(mProgressDialog, context);
        mConfig = getBaseConfig("TakeStock/AddTakeStock");
        mConfig.setParams(params);
        mHttpUtils.getToJson(mConfig, httpResult);
    }

    /**
     * 刷条码添加商品到购物车
     *
     * @param context
     * @param params
     * @param httpResult
     */
    public void addGoodsToShopping(Context context, Map<String, String> params, HttpUtils.IHttpResult
            httpResult) {
        mProgressDialog = DialogUtil.getProgressDialog(context, "添加中...");
        mHttpUtils = new HttpUtils(mProgressDialog, context);
        mConfig = getBaseConfig("ShoppingCart/AddItem");
        mConfig.setParams(params);
        mConfig.setCls(OpenOrderModel.class);
        mHttpUtils.getToJson(mConfig, httpResult);
    }

    /**
     * 获取购物车列表
     *
     * @param context
     * @param httpResult
     */
    public void getShoppingList(Context context, HttpUtils.IHttpResult httpResult) {
        mProgressDialog = DialogUtil.getProgressDialog(context, "获取中...");
        mHttpUtils = new HttpUtils(mProgressDialog, context);
        mConfig = getBaseConfig("ShoppingCart/GetCarItems");
        mConfig.setCls(OpenOrderModel.CarItemsBean.class);
        mHttpUtils.getToJson(mConfig, httpResult);
    }

    /**
     * 修改购物车商品优惠价
     *
     * @param context
     * @param httpResult
     */
    public void changeGoodsPrice(Context context, Map<String, String> params, HttpUtils.IHttpResult httpResult) {
        mProgressDialog = DialogUtil.getProgressDialog(context, "修改中...");
        mHttpUtils = new HttpUtils(mProgressDialog, context);
        mConfig = getBaseConfig("ShoppingCart/EditPrice");
        mConfig.setParams(params);
        mConfig.setCls(OpenOrderModel.CarItemsBean.class);
        mHttpUtils.getToJson(mConfig, httpResult);
    }

    /**
     * 修改购物车商品数量
     *
     * @param context
     * @param httpResult
     */
    public void changeGoodsNum(Context context, Map<String, String> params, HttpUtils.IHttpResult httpResult) {
        mProgressDialog = DialogUtil.getProgressDialog(context, "修改中...");
        mHttpUtils = new HttpUtils(mProgressDialog, context);
        mConfig = getBaseConfig("ShoppingCart/EditNumber");
        mConfig.setCls(OpenOrderModel.CarItemsBean.class);
        mConfig.setParams(params);
        mHttpUtils.getToJson(mConfig, httpResult);
    }

    /**
     * 删除购物车商品
     *
     * @param context
     * @param httpResult
     */
    public void deleteGoodsItem(Context context, Map<String, String> params, HttpUtils.IHttpResult httpResult) {
        mProgressDialog = DialogUtil.getProgressDialog(context, "正在删除...");
        mHttpUtils = new HttpUtils(mProgressDialog, context);
        mConfig = getBaseConfig("ShoppingCart/RemoveItem");
        mConfig.setCls(OpenOrderModel.CarItemsBean.class);
        mConfig.setParams(params);
        mHttpUtils.getToJson(mConfig, httpResult);
    }

    /**
     * 批量删除商品
     */
    public void deleteGoodsItems(Context context, String data, HttpUtils.IHttpResult httpResult) {
        mProgressDialog = DialogUtil.getProgressDialog(context, "正在删除...");
        mHttpUtils = new HttpUtils(mProgressDialog, context);
        mConfig = getBaseConfig("ShoppingCart/RemoveItems");
        mConfig.setBody(data);
        mConfig.setCls(OpenOrderModel.CarItemsBean.class);
        mHttpUtils.postToJson(mConfig, httpResult);
    }

    /**
     * 购物车结算
     *
     * @param context
     * @param httpResult
     */
    public void gotoPayGoods(Context context, HttpUtils.IHttpResult httpResult) {
        mProgressDialog = DialogUtil.getProgressDialog(context, "结算中...");
        mHttpUtils = new HttpUtils(mProgressDialog, context);
        mConfig = getBaseConfig("ShoppingCart/DoPay");
        mHttpUtils.getToJson(mConfig, httpResult);
    }

    /**
     * 结算新增订单（促销情况下使用）
     *
     * @param context
     * @param httpResult
     */
    public void gotoNewPayGoods(Context context, Map<String, String> params, HttpUtils.IHttpResult httpResult) {
        mProgressDialog = DialogUtil.getProgressDialog(context, "结算中...");
        mHttpUtils = new HttpUtils(mProgressDialog, context);
        mConfig = getBaseConfig("ShoppingCart/AddOrder");
        mConfig.setParams(params);
        mConfig.setCls(DoPayGoodsModel.class);
        mHttpUtils.postToJson(mConfig, httpResult);
    }

    /**
     * 整单优惠
     *
     * @param context
     * @param httpResult
     */
    public void orderPreferential(Context context, Map<String, String> params, HttpUtils.IHttpResult httpResult) {
        mProgressDialog = DialogUtil.getProgressDialog(context, "操作中...");
        mHttpUtils = new HttpUtils(mProgressDialog, context);
        mConfig = getBaseConfig("ShoppingCart/OrderPreferential");
        mConfig.setParams(params);
        mHttpUtils.getToJson(mConfig, httpResult);
    }

    /**
     * 日结汇总
     */
    public void getDaySummary(Context context, Map<String, String> params, HttpUtils.IHttpResult httpResult) {
        mProgressDialog = DialogUtil.getProgressDialog(context, "获取中...");
        mHttpUtils = new HttpUtils(mProgressDialog, context);
        mConfig = getBaseConfig("report/sale/DaySummary");
        mConfig.setParams(params);
        mConfig.setCls(EverydayAccountModel.class);
        mHttpUtils.getToJson(mConfig, httpResult);
    }

    /**
     * 月结汇总
     */
    public void getMonthSummary(Context context, Map<String, String> params, HttpUtils.IHttpResult httpResult) {
        mProgressDialog = DialogUtil.getProgressDialog(context, "获取中...");
        mHttpUtils = new HttpUtils(mProgressDialog, context);
        mConfig = getBaseConfig("report/sale/MonthSummary");
        mConfig.setParams(params);
        mConfig.setCls(EverydayAccountModel.class);
        mHttpUtils.getToJson(mConfig, httpResult);
    }


    /**
     * 门店日结明细
     */
    public void getDayDetail(Context context, Map<String, String> params, HttpUtils.IHttpResult httpResult) {
        mProgressDialog = DialogUtil.getProgressDialog(context, "获取中...");
        mHttpUtils = new HttpUtils(mProgressDialog, context);
        mConfig = getBaseConfig("report/sale/DayDetail");
        mConfig.setParams(params);
        mConfig.setCls(AllAccountDetailModel.class);
        mHttpUtils.getToJson(mConfig, httpResult);
    }

    /**
     * 门店月结明细
     */
    public void getMonthDetail(Context context, Map<String, String> params, HttpUtils.IHttpResult httpResult) {
        mProgressDialog = DialogUtil.getProgressDialog(context, "获取中...");
        mHttpUtils = new HttpUtils(mProgressDialog, context);
        mConfig = getBaseConfig("report/sale/MonthDetail");
        mConfig.setParams(params);
        mConfig.setCls(AllAccountDetailModel.class);
        mHttpUtils.getToJson(mConfig, httpResult);
    }

    /**
     * 获取门店
     *
     * @param context
     * @param httpResult
     */
    public void getStore(Context context, boolean isShow, HttpUtils.IHttpResult httpResult) {
        mProgressDialog = DialogUtil.getProgressDialog(context, "获取中...");
        mHttpUtils = new HttpUtils(mProgressDialog, context, isShow);
        mConfig = getBaseConfig("store");
        mConfig.setElement(StoreModel.class);
        mHttpUtils.getToJson(mConfig, httpResult);
    }

    /**
     * 获取品类统计表
     *
     * @param context
     * @param params
     * @param httpResult
     */
    public void getTypeStatistic(Context context, Map<String, String> params, HttpUtils.IHttpResult httpResult) {
        mProgressDialog = DialogUtil.getProgressDialog(context, "获取中...");
        mHttpUtils = new HttpUtils(mProgressDialog, context);
        mConfig = getBaseConfig("report/sale/Category");
        mConfig.setParams(params);
        mConfig.setElement(TypeStatisticModel.class);
        mHttpUtils.getToJson(mConfig, httpResult);
    }

    /**
     * 获取品牌统计表
     *
     * @param context
     * @param params
     * @param httpResult
     */
    public void getBrandStatistic(Context context, Map<String, String> params, HttpUtils.IHttpResult httpResult) {
        mProgressDialog = DialogUtil.getProgressDialog(context, "获取中...");
        mHttpUtils = new HttpUtils(mProgressDialog, context);
        mConfig = getBaseConfig("report/sale/Brand");
        mConfig.setParams(params);
        mConfig.setElement(TypeStatisticModel.class);
        mHttpUtils.getToJson(mConfig, httpResult);
    }

    /**
     * 获取商品统计表
     *
     * @param context
     * @param params
     * @param httpResult
     */
    public void getProductStatistic(Context context, Map<String, String> params, HttpUtils.IHttpResult httpResult) {
        mProgressDialog = DialogUtil.getProgressDialog(context, "获取中...");
        mHttpUtils = new HttpUtils(mProgressDialog, context);
        mConfig = getBaseConfig("report/sale/Product");
        mConfig.setParams(params);
        mConfig.setElement(GoodsStatisticModel.class);
        mHttpUtils.getToJson(mConfig, httpResult);
    }

    /**
     * 获取日结统计表
     *
     * @param context
     * @param params
     * @param httpResult
     */
    public void getDayStatistic(Context context, Map<String, String> params, HttpUtils.IHttpResult httpResult) {
        mProgressDialog = DialogUtil.getProgressDialog(context, "获取中...");
        mHttpUtils = new HttpUtils(mProgressDialog, context);
        mConfig = getBaseConfig("report/sale/DaySummaryDetail");
        mConfig.setParams(params);
        mConfig.setCls(DayStatisticTableModel.class);
        mHttpUtils.getToJson(mConfig, httpResult);
    }

    /**
     * 获取日结统计表
     *
     * @param context
     * @param params
     * @param httpResult
     */
    public void getMonthStatistic(Context context, Map<String, String> params, HttpUtils.IHttpResult httpResult) {
        mProgressDialog = DialogUtil.getProgressDialog(context, "获取中...");
        mHttpUtils = new HttpUtils(mProgressDialog, context);
        mConfig = getBaseConfig("report/sale/MonthSummaryDetail");
        mConfig.setParams(params);
        mConfig.setCls(DayStatisticTableModel.class);
        mHttpUtils.getToJson(mConfig, httpResult);
    }

    /**
     * 购物卡和储值卡支付
     *
     * @param context
     * @param params
     * @param httpResult
     */
    public void doPayByCard(Context context, Map<String, String> params, HttpUtils.IHttpResult httpResult) {
        mProgressDialog = DialogUtil.getProgressDialog(context, "支付中...");
        mHttpUtils = new HttpUtils(mProgressDialog, context);
        mConfig = getBaseConfig("Pay/DoPayByCard");
        mConfig.setParams(params);
        mHttpUtils.getToJson(mConfig, httpResult);
    }


    /**
     * 优惠券支付
     *
     * @param context
     * @param httpResult
     */
    public void doPayByCoupon(Context context, String couponNo, HttpUtils.IHttpResult httpResult) {
        mProgressDialog = DialogUtil.getProgressDialog(context, "支付中...");
        mHttpUtils = new HttpUtils(mProgressDialog, context);
        mConfig = getBaseConfig("Pay/DoPayByCoupon?couponNo=" + couponNo);
        mHttpUtils.getToJson(mConfig, httpResult);
    }

    /**
     * 聚合支付被扫
     *
     * @param context
     * @param params
     * @param httpResult
     */
    public void doPayScanByBuyer(Context context, Map<String, String> params, HttpUtils.IHttpResult httpResult) {
        mProgressDialog = DialogUtil.getProgressDialog(context, "获取中...");
        mHttpUtils = new HttpUtils(mProgressDialog, context);
        mConfig = getBaseConfig("Pay/DoPayScanByBuyer");
        mConfig.setParams(params);
        mHttpUtils.getToJson(mConfig, httpResult);
    }

    /**
     * 聚合支付主扫
     *
     * @param context
     * @param params
     * @param httpResult
     */
    public void doPayScanByCode(Context context, Map<String, String> params, HttpUtils.IHttpResult httpResult) {
        mProgressDialog = DialogUtil.getProgressDialog(context, "支付中...");
        mHttpUtils = new HttpUtils(mProgressDialog, context);
        mConfig = getBaseConfig("Pay/DoPayScanByCode");
        mConfig.setParams(params);
        mHttpUtils.getToJson(mConfig, httpResult);
    }

    /**
     * 支付宝被扫
     *
     * @param context
     * @param params
     * @param httpResult
     */
    public void doPayScanZFBByBuyer(Context context, Map<String, String> params, HttpUtils.IHttpResult httpResult) {
        mProgressDialog = DialogUtil.getProgressDialog(context, "获取中...");
        mHttpUtils = new HttpUtils(mProgressDialog, context);
        mConfig = getBaseConfig("Pay/DoPayScanZFBByBuyer");
        mConfig.setParams(params);
        mHttpUtils.getToJson(mConfig, httpResult);
    }

    /**
     * 支付宝主扫
     *
     * @param context
     * @param params
     * @param httpResult
     */
    public void doPayScanZFBByCode(Context context, Map<String, String> params, HttpUtils.IHttpResult httpResult) {
        mProgressDialog = DialogUtil.getProgressDialog(context, "支付中...");
        mHttpUtils = new HttpUtils(mProgressDialog, context);
        mConfig = getBaseConfig("Pay/DoPayScanZFBByCode");
        mConfig.setParams(params);
        mHttpUtils.getToJson(mConfig, httpResult);
    }

    /**
     * 微信被扫
     *
     * @param context
     * @param params
     * @param httpResult
     */
    public void doPayScanWXByBuyer(Context context, Map<String, String> params, HttpUtils.IHttpResult httpResult) {
        mProgressDialog = DialogUtil.getProgressDialog(context, "获取中...");
        mHttpUtils = new HttpUtils(mProgressDialog, context);
        mConfig = getBaseConfig("Pay/DoPayScanWXByBuyer");
        mConfig.setParams(params);
        mHttpUtils.getToJson(mConfig, httpResult);
    }

    /**
     * 微信主扫
     *
     * @param context
     * @param params
     * @param httpResult
     */
    public void doPayScanWXByCode(Context context, Map<String, String> params, HttpUtils.IHttpResult httpResult) {
        mProgressDialog = DialogUtil.getProgressDialog(context, "支付中...");
        mHttpUtils = new HttpUtils(mProgressDialog, context);
        mConfig = getBaseConfig("Pay/DoPayScanWXByCode");
        mConfig.setParams(params);
        mHttpUtils.getToJson(mConfig, httpResult);
    }

    /**
     * 订单完成
     *
     * @param context
     * @param httpResult
     */
    public void getPayResult(Context context, Map<String, String> params, boolean isShow, HttpUtils.IHttpResult
            httpResult) {
        if (isShow) {
            mProgressDialog = DialogUtil.getProgressDialog(context, "提交中...");
        }
        mHttpUtils = new HttpUtils(isShow ? mProgressDialog : null, context);
        mConfig = getBaseConfig("Pay/GetPayResult");
        mConfig.setParams(params);
        mHttpUtils.getToJson(mConfig, httpResult);
    }

    /**
     * 订单完成
     *
     * @param context
     * @param httpResult
     */
    public void finishOrder(Context context, String body, HttpUtils.IHttpResult httpResult) {
        mProgressDialog = DialogUtil.getProgressDialog(context, "提交中...");
        mHttpUtils = new HttpUtils(mProgressDialog, context);
        mConfig = getBaseConfig("ShoppingCart/FinishOrder");
        mConfig.setBody(body);
        mHttpUtils.postToJson(mConfig, httpResult);
    }
}
